﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Reflection;
using System.Xml;
using OgilvyOne.Model;
using OgilvyOne.Utility;

namespace OgilvyOne.BLL
{
    /// <summary>
    /// 取标签定义值,基类
    /// 所有继承类都可
    /// <cms:label value="标签定义名"></cms:label>
    /// 值取
    /// </summary>
    abstract class LabelCommonLabel : CommonLabel
    {
        public LabelCommonLabel(CommonModel model):base(model)
        {

        }
        protected string labelname;  //标签定义名
        

        /// <summary>
        /// 标签名
        /// </summary>
        public string LabelName
        {
            set { labelname = value; }
            get { return labelname; }
        }
        /// <summary>
        /// 获取标签值
        /// </summary>
        /// <returns></returns>
        public string GetLabelValue()
        {
            string value = ((TemplateLabelModel)new TemplateLabelBll().GetLabelMap()[LabelName]).Value;
            if (value == null) value = "";
            return value;
        }
        /// <summary>
        /// 转换文字为XML文档
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public XmlDocument GetLabelValueXmlDocument(string value)
        {
            XmlDocument doc = new XmlDocument();
            XmlDeclaration decl = doc.CreateXmlDeclaration("1.0", "UTF-8", null);
            doc.AppendChild(decl);
            doc.LoadXml(value);
            return doc;
        }

        public override sealed string GetLabelHtml()
        {
            if (model != null && model.Model != null && model.Model.IsHtmlFile)
            {//是否正生成HTML
                TemplateLabelModel tlm = (TemplateLabelModel)new TemplateLabelBll().GetLabelMap()[LabelName];
                if (tlm.Ishtml == CmsConstants.YES)
                {
                    return "<!--#include virtual=\"/include/tag/" + tlm.HtmlFileName + "\"-->";
                }
            }
            return GetLabelLabelHtml();
        }
        public abstract string GetLabelLabelHtml();
    }
}
